package com.example.idachuappone.cook.item;

import java.util.HashMap;
import java.util.Map;

import org.json.JSONException;
import org.json.JSONObject;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.idachuappone.BaseActivity;
import com.example.idachuappone.LoadingActivity;
import com.example.idachuappone.MainTWo;
import com.example.idachuappone.R;
import com.example.idachuappone.index.alipay.Result;
import com.example.idachuappone.index.dto.WelcomeDto;
import com.example.idachuappone.index.item.YouHuiMaActivity;
import com.example.idachuappone.index.weixinpay.Constants;
import com.example.idachuappone.person.entity.Order;
import com.example.idachuappone.person.entity.QuanResults;
import com.example.idachuappone.person.member.MemberDetailActivity;
import com.example.idachuappone.person.member.MemberTypeActivity;
import com.example.idachuappone.person.method.UserInfoMethod;
import com.example.idachuappone.person.method.UserInfoMethod.CallBack;
import com.example.idachuappone.person.method.UserInfoMethod.CallBackString;
import com.example.idachuappone.promptly.entity.UserInfo;
import com.example.idachuappone.utils.AppShareData;
import com.example.idachuappone.utils.BitmapUtilHelper;
import com.example.idachuappone.utils.CheckUtil;
import com.example.idachuappone.utils.ComUtil;
import com.example.idachuappone.utils.Constant;
import com.example.idachuappone.utils.CusProSmallBgDialog;
import com.example.idachuappone.utils.MainToast;
import com.example.idachuappone.utils.NetUtil;
import com.example.idachuappone.utils.Utils;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapDisplayConfig;
import com.lidroid.xutils.bitmap.BitmapGlobalConfig.BitmapCacheManagementTask;
import com.lidroid.xutils.bitmap.callback.BitmapLoadCallBack;
import com.lidroid.xutils.bitmap.callback.BitmapLoadFrom;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.tencent.mm.sdk.modelpay.PayReq;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.WXAPIFactory;

public class PayPromptlyActivity extends BaseActivity implements OnClickListener {
	private static final int RQF_PAY = 290;
	public static int code;
	private IWXAPI api;
	private Button btn_back;
	private Button btn_ok;
	private BitmapUtils bu;
	private String coupon_id;
	private CusProSmallBgDialog cusProDialog;
	private Handler handler;
	private ImageView img_alipay;
	private ImageView img_head1;
	private ImageView img_weixin;
	private ImageView img_xianxia;
	private ImageView img_yes_member;
	private ImageView img_youhui_tiao_jian;
	private int index_item;
	private boolean isOrder;
	private boolean isUpdate;
	private boolean isXianShang;
	private boolean isprom;
	private LinearLayout ll_alipay;
	private LinearLayout ll_cook_no;
	private LinearLayout ll_cook_yes;
	private LinearLayout ll_member_money_no;
	private LinearLayout ll_meno;
	private LinearLayout ll_no_member;
	private LinearLayout ll_order;
	private LinearLayout ll_quan_xuan;
	private LinearLayout ll_weixin;
	private LinearLayout ll_xianxia;
	private LinearLayout ll_yes_member;
	private Dialog mCusProDialog;
	private int memberType;
	public double member_money;
	private Order order;
	private String orderid;
	private int payType;
	private QuanResults quanResults;
	private double temp;
	private TextView tv_alipay_youhui;
	private TextView tv_daimai;
	private TextView tv_member_money;
	private TextView tv_meno;
	private TextView tv_name;
	private TextView tv_package1;
	private TextView tv_pay_money;
	private TextView tv_service_for;
	private TextView tv_tags_greed;
	private TextView tv_time1;
	private TextView tv_user_address;
	private TextView tv_user_name;
	private TextView tv_user_phone;
	private TextView tv_weixin_youhui;
	private TextView tv_youhui_name;

	class AnonymousClass_12 extends Thread {
		private final/* synthetic */String val$info;

		AnonymousClass_12(String str) {
			this.val$info = str;
		}

		@Override
		public void run() {

			String result = "";// new AliPay(PayPromptlyActivity.this,
								// PayPromptlyActivity.this.handler).pay(this.val$info);
			Message msg = PayPromptlyActivity.this.handler.obtainMessage(RQF_PAY);
			msg.obj = result;
			PayPromptlyActivity.this.handler.sendMessage(msg);
		}
	}

	private static class GetPrepayIdResult {
		public int errCode;
		public String errMsg;
		public LocalRetCode localRetCode;
		public String noncestr;
		public String prepayId;
		public String sign;
		public String timestamp;

		private GetPrepayIdResult() {
			this.localRetCode = LocalRetCode.ERR_OTHER;
		}

		public void parseFrom(String content) {
			if (content == null || content.length() <= 0) {
				this.localRetCode = LocalRetCode.ERR_JSON;
				return;
			}
			try {
				JSONObject json = new JSONObject(content);
				if (json.has("data")) {
					this.prepayId = json.getJSONObject("data").getString("prepayid");
					this.sign = json.getJSONObject("data").getString("sign");
					this.noncestr = json.getJSONObject("data").getString("noncestr");
					this.timestamp = json.getJSONObject("data").getString("timestamp");
					this.localRetCode = LocalRetCode.ERR_OK;
				} else {
					this.localRetCode = LocalRetCode.ERR_JSON;
				}
				this.errCode = json.getInt("errcode");
				this.errMsg = json.getString("errmsg");
			} catch (Exception e) {
				this.localRetCode = LocalRetCode.ERR_JSON;
			}
		}
	}

	private enum LocalRetCode {
		ERR_OK,
		ERR_HTTP,
		ERR_JSON,
		ERR_OTHER;

	}

	class AnonymousClass_14 extends RequestCallBack<String> {
		private final/* synthetic */String val$pay_method;

		AnonymousClass_14(String str) {
			this.val$pay_method = str;
		}

		@Override
		public void onStart() {
			super.onStart();
			PayPromptlyActivity.this.mCusProDialog.show();
		}

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {
			PayPromptlyActivity.this.mCusProDialog.dismiss();
			try {
				JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
				if (jsonObject.getInt("code") == 10000) {
					PayPromptlyActivity.this.isUpdate = false;
					if (!"3".equals(this.val$pay_method)) {
						code = 100;
					}
					Order orderback = new Order();
					orderback.parseJson(jsonObject.getJSONObject("data"));
					if (Integer.parseInt(orderback.getStatus()) != 5) {
						code = -10000;
						Intent intent = new Intent(PayPromptlyActivity.this, MainTWo.class);
						intent.putExtra("isgoorder", true);
						PayPromptlyActivity.this.startActivity(intent);
						return;
					} else if (PayPromptlyActivity.this.payType == 0) {
						PayPromptlyActivity.this.payWeixin();
						return;
					} else if (PayPromptlyActivity.this.payType == 1) {
						PayPromptlyActivity.this.payWithAlipay();
						return;
					} else if (PayPromptlyActivity.this.payType == 2) {
						PayPromptlyActivity.this.payMember();
						return;
					} else {
						return;
					}
				}
				MainToast.show(PayPromptlyActivity.this, jsonObject.optString("error"), 0);
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		@Override
		public void onFailure(HttpException arg0, String arg1) {
			PayPromptlyActivity.this.mCusProDialog.dismiss();
			MainToast.show(PayPromptlyActivity.this, PayPromptlyActivity.this.getResources()
					.getString(R.string.netFail), 1);
		}
	}

	public PayPromptlyActivity() {
		this.isXianShang = true;
		this.payType = 0;
		this.isUpdate = true;
		this.temp = -1.0d;
		this.index_item = -1;
		this.handler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				switch (msg.what) {
				case RQF_PAY /* 290 */:
					Result.sResult = (String) msg.obj;
					if (Result.isSucc()) {
						code = -10000;
						Intent intent = new Intent(PayPromptlyActivity.this, MainTWo.class);
						intent.putExtra("isgoorder", true);
						PayPromptlyActivity.this.startActivity(intent);
						return;
					}
					MainToast.show(PayPromptlyActivity.this, "\u652f\u4ed8\u672a\u6210\u529f", 0);
				default:
				}
			}
		};
	}

	static {
		code = -10000;
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_pay_promptly_two);
		this.api = WXAPIFactory.createWXAPI(this, Constants.APP_ID, false);
		this.api.registerApp(Constants.APP_ID);
		this.isprom = getIntent().getBooleanExtra("isprom", false);
		this.isOrder = getIntent().getBooleanExtra("isorder", false);
		this.orderid = getIntent().getStringExtra("orderid");
		this.mCusProDialog = ComUtil.createCusProgressSmallBlackBgDialog(this);
		this.cusProDialog = new CusProSmallBgDialog(this);
		this.bu = BitmapUtilHelper.createBitmapUtil(this);
		initView();
		checkNet();
	}

	private void checkNet() {
		if (CheckUtil.checkNet(this)) {
			setOrder(this.orderid);
		} else {
			MainToast.show(this, getResources().getString(R.string.txt_network), 0);
		}
	}

	private void getQuanShu() {
		if (CheckUtil.checkNet(this)) {
			NetUtil.get(this, new StringBuilder(Constant.MYYOUHUIMAORDERID).append(this.order.getId()).toString(), 100,
					new RequestCallBack<String>() {
						@Override
						public void onSuccess(ResponseInfo<String> responseInfo) {
							try {
								JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
								if (jsonObject.getInt("code") == 10000) {
									String size = jsonObject.getJSONObject("data").getString("total");
									if (size.equals("0")) {
										PayPromptlyActivity.this.tv_youhui_name
												.setText("\u6ca1\u6709\u53ef\u7528\u4f18\u60e0\u5238");
									} else {
										PayPromptlyActivity.this.tv_youhui_name.setText("\u4f60\u6709" + size
												+ "\u5f20\u53ef\u7528\u4f18\u60e0\u5238");
									}
								}
							} catch (Exception e) {
								e.printStackTrace();
							}
						}

						@Override
						public void onFailure(HttpException arg0, String arg1) {
						}
					});
		} else {
			MainToast.show(this, getResources().getString(R.string.txt_network), 0);
		}
	}

	private void setOrder(String id) {
		NetUtil.get(this, new StringBuilder(Constant.PROMPTLY_DETAIL).append(id).toString(), 100,
				new RequestCallBack<String>() {
					@Override
					public void onStart() {
						super.onStart();
						PayPromptlyActivity.this.mCusProDialog.show();
					}

					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						try {
							JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
							if (jsonObject.getInt("code") == 10000) {
								PayPromptlyActivity.this.order = new Order();
								PayPromptlyActivity.this.order = PayPromptlyActivity.this.order.parseJson(jsonObject
										.getJSONObject("data"));
								if (LoadingActivity.welcome == null || LoadingActivity.welcome.getAwards() == null
										|| LoadingActivity.welcome.getAwards().getWeixin() == null) {
									PayPromptlyActivity.this.initIsWeiXinJIan();
								} else {
									PayPromptlyActivity.this.tv_weixin_youhui.setVisibility(0);
									PayPromptlyActivity.this.tv_weixin_youhui.setText("("
											+ LoadingActivity.welcome.getAwards().getWeixin().getText() + ")");
									PayPromptlyActivity.this.initData();
									PayPromptlyActivity.this.initMemberData();
								}
								if (LoadingActivity.welcome == null || LoadingActivity.welcome.getAwards() == null
										|| LoadingActivity.welcome.getAwards().getAlipay() == null) {
									PayPromptlyActivity.this.initIsAlipayJIan();
									return;
								}
								PayPromptlyActivity.this.tv_alipay_youhui.setVisibility(0);
								PayPromptlyActivity.this.tv_alipay_youhui.setText("("
										+ LoadingActivity.welcome.getAwards().getAlipay().getText() + ")");
								return;
							}
							MainToast.show(PayPromptlyActivity.this, jsonObject.optString("error"), 0);
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void onFailure(HttpException arg0, String arg1) {
						PayPromptlyActivity.this.mCusProDialog.dismiss();
						MainToast.show(PayPromptlyActivity.this,
								PayPromptlyActivity.this.getResources().getString(R.string.netFail), 0);
					}
				});
	}

	private void initIsAlipayJIan() {
		NetUtil.get(this, Constant.PACKAGES, 100, new RequestCallBack<String>() {
			@Override
			public void onFailure(HttpException arg0, String arg1) {
			}

			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String json = NetUtil.unescapeUnicode(responseInfo.result);
				try {
					LoadingActivity.welcome = new WelcomeDto().getWelcome(PayPromptlyActivity.this, json);
					if (LoadingActivity.welcome.getAwards().getAlipay() != null) {
						PayPromptlyActivity.this.tv_alipay_youhui.setVisibility(0);
						PayPromptlyActivity.this.tv_alipay_youhui.setText("("
								+ LoadingActivity.welcome.getAwards().getAlipay().getText() + ")");
						return;
					}
					PayPromptlyActivity.this.tv_alipay_youhui
							.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
				} catch (Exception e) {
					MainToast.show(PayPromptlyActivity.this, e.getMessage(), 0);
				}
			}
		});
	}

	private void initIsWeiXinJIan() {
		NetUtil.get(this, Constant.PACKAGES, 100, new RequestCallBack<String>() {
			@Override
			public void onFailure(HttpException arg0, String arg1) {
			}

			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String json = NetUtil.unescapeUnicode(responseInfo.result);
				try {
					LoadingActivity.welcome = new WelcomeDto().getWelcome(PayPromptlyActivity.this, json);
					if (LoadingActivity.welcome.getAwards().getWeixin() != null) {
						PayPromptlyActivity.this.tv_weixin_youhui.setText("("
								+ LoadingActivity.welcome.getAwards().getWeixin().getText() + ")");
						PayPromptlyActivity.this.tv_weixin_youhui.setVisibility(0);
					} else {
						PayPromptlyActivity.this.tv_weixin_youhui
								.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
					}
					PayPromptlyActivity.this.initData();
					PayPromptlyActivity.this.initMemberData();
				} catch (Exception e) {
					MainToast.show(PayPromptlyActivity.this, e.getMessage(), 0);
				}
			}
		});
	}

	private void initData() {
		int length = BitmapCacheManagementTask.MESSAGE_FLUSH;
		if (this.order.getKitchener() != null) {
			this.isprom = false;
		} else {
			this.isprom = true;
		}
		if (Integer.parseInt(this.order.getPay_type()) != 0) {
			if (this.order.getQuanResults() == null || this.order.getQuanResults().getId() == null) {
				getQuanShu();
			} else {
				this.coupon_id = this.order.getQuanResults().getId();
				this.tv_youhui_name.setText("\u7701" + this.order.getQuanResults().getDiscount() + "\u5143("
						+ this.order.getQuanResults().getCoupon().getName() + ")");
			}
			this.tv_pay_money.setText(ComUtil.FormatDistance(this.order.getPay_price()));
		} else {
			this.tv_pay_money.setText(ComUtil.FormatDistance(this.order.getPackage_price()));
			getQuanShu();
		}
		if (this.isprom) {
			this.ll_cook_yes.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
			this.ll_cook_no.setVisibility(0);
		} else {
			this.ll_cook_yes.setVisibility(0);
			this.ll_cook_no.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
			this.bu.display(this.img_head1, this.order.getKitchener().getHead_small(), new BitmapLoadCallBack<View>() {
				@Override
				public void onLoadCompleted(View view, String arg1, Bitmap bitmap, BitmapDisplayConfig arg3,
						BitmapLoadFrom arg4) {
					((ImageView) view).setImageBitmap(BitmapUtilHelper.getCroppedRoundBitmap(bitmap,
							Utils.dip2px(PayPromptlyActivity.this, 22.0f)));
				}

				@Override
				public void onLoadFailed(View arg0, String arg1, Drawable arg2) {
				}
			});
			this.tv_name.setText(this.order.getKitchener().getName());
			this.tv_service_for.setText(this.order.getKitchener().getService_for());
			if (this.order.getKitchener().getTags() == null || this.order.getKitchener().getTags().size() <= 0) {
				this.tv_tags_greed.setText("\u64c5\u957f\u5bb6\u5e38\u83dc");
			} else {
				String tag = "";
				if (this.order.getKitchener().getTags().size() < 2) {
					length = this.order.getKitchener().getTags().size();
				}
				for (int i = 0; i < length; i++) {
					tag = new StringBuilder(String.valueOf(tag))
							.append(this.order.getKitchener().getTags().get(i).getName()).append("   ").toString();
				}
				this.tv_tags_greed.setText("\u64c5\u957f" + tag);
			}
		}
		if (this.order.getIngredient() == 0) {
			this.tv_daimai.setText("\u4ee3\u4e70\u98df\u6750");
		} else {
			this.tv_daimai.setText("\u81ea\u5907\u98df\u6750");
		}
		this.tv_package1.setText(new StringBuilder(String.valueOf(this.order.getPackage_name())).append("/")
				.append(this.order.getPackage_price()).append("\u5143").toString());
		this.tv_time1.setText(ComUtil.FormatCalenderTime1(this.order.getDate()));
		if (this.order.getMemo() == null || this.order.getMemo().replace(" ", "").trim().length() <= 0) {
			this.ll_meno.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
		} else {
			this.ll_meno.setVisibility(0);
			this.tv_meno.setText(this.order.getMemo());
		}
		setServiceAddressView();
	}

	private void setServiceAddressView() {
		this.tv_user_name.setText(this.order.getName());
		this.tv_user_phone.setText(this.order.getPhone());
		this.tv_user_address.setText(new StringBuilder(String.valueOf(this.order.getArea()))
				.append(this.order.getCommunity()).append(this.order.getDoor_number()).toString());
	}

	private void initView() {
		this.tv_alipay_youhui = (TextView) findViewById(R.id.tv_alipay_youhui);
		this.tv_weixin_youhui = (TextView) findViewById(R.id.tv_weixin_youhui);
		this.tv_daimai = (TextView) findViewById(R.id.tv_daimai);
		this.tv_service_for = (TextView) findViewById(R.id.tv_service_for);
		this.tv_tags_greed = (TextView) findViewById(R.id.tv_tags_greed);
		this.tv_user_name = (TextView) findViewById(R.id.tv_user_name);
		this.tv_user_phone = (TextView) findViewById(R.id.tv_user_phone);
		this.tv_user_address = (TextView) findViewById(R.id.tv_user_address);
		this.ll_cook_yes = (LinearLayout) findViewById(R.id.ll_cook_yes);
		this.ll_cook_no = (LinearLayout) findViewById(R.id.ll_cook_no);
		this.img_head1 = (ImageView) findViewById(R.id.img_head1);
		this.tv_package1 = (TextView) findViewById(R.id.tv_package1);
		this.tv_time1 = (TextView) findViewById(R.id.tv_time1);
		this.tv_name = (TextView) findViewById(R.id.tv_name);
		this.ll_xianxia = (LinearLayout) findViewById(R.id.ll_xianxia);
		this.ll_xianxia.setOnClickListener(this);
		this.ll_weixin = (LinearLayout) findViewById(R.id.ll_weixin);
		this.ll_weixin.setOnClickListener(this);
		this.ll_alipay = (LinearLayout) findViewById(R.id.ll_alipay);
		this.ll_alipay.setOnClickListener(this);
		this.img_xianxia = (ImageView) findViewById(R.id.img_xianxia);
		this.img_alipay = (ImageView) findViewById(R.id.img_alipay);
		this.img_weixin = (ImageView) findViewById(R.id.img_weixin);
		this.btn_back = (Button) findViewById(R.id.btn_back);
		this.btn_back.setOnClickListener(this);
		this.btn_ok = (Button) findViewById(R.id.btn_ok);
		this.btn_ok.setOnClickListener(this);
		this.ll_quan_xuan = (LinearLayout) findViewById(R.id.ll_quan_xuan);
		this.ll_quan_xuan.setOnClickListener(this);
		this.tv_pay_money = (TextView) findViewById(R.id.tv_pay_money);
		this.tv_youhui_name = (TextView) findViewById(R.id.tv_youhui_name);
		this.img_youhui_tiao_jian = (ImageView) findViewById(R.id.img_youhui_tiao_jian);
		this.ll_meno = (LinearLayout) findViewById(R.id.ll_meno);
		this.tv_meno = (TextView) findViewById(R.id.tv_meno);
		this.ll_order = (LinearLayout) findViewById(R.id.ll_order);
		if (this.isOrder) {
			this.ll_order.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
		} else {
			this.ll_order.setVisibility(0);
		}
		initMemberView();
	}

	private void initMemberView() {
		this.ll_yes_member = (LinearLayout) findViewById(R.id.ll_yes_member);
		this.ll_yes_member.setOnClickListener(this);
		this.img_yes_member = (ImageView) findViewById(R.id.img_yes_member);
		this.ll_member_money_no = (LinearLayout) findViewById(R.id.ll_member_money_no);
		this.tv_member_money = (TextView) findViewById(R.id.tv_member_money);
		this.ll_no_member = (LinearLayout) findViewById(R.id.ll_no_member);
		this.ll_no_member.setOnClickListener(this);
	}

	private void initMemberData() {
		UserInfoMethod.getUserInfo(this, new CallBack() {
			@Override
			public void onSuccess(UserInfo userInfo) {
				if (userInfo.getDegree() == 0) {
					PayPromptlyActivity.this.mCusProDialog.dismiss();
					PayPromptlyActivity.this.ll_no_member.setVisibility(0);
					PayPromptlyActivity.this.ll_yes_member
							.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
					PayPromptlyActivity.this.ll_weixin.performClick();
					return;
				}
				PayPromptlyActivity.this.memberType = userInfo.getDegree();
				PayPromptlyActivity.this.ll_no_member
						.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
				PayPromptlyActivity.this.ll_yes_member.setVisibility(0);
				PayPromptlyActivity.this.setYuE();
			}

			@Override
			public void onFail() {
				PayPromptlyActivity.this.mCusProDialog.dismiss();
				MainToast.show(PayPromptlyActivity.this,
						PayPromptlyActivity.this.getResources().getString(R.string.netFail), 0);
			}
		});
	}

	private void setYuE() {
		UserInfoMethod.getUserYuE(this, new CallBackString() {
			@Override
			public void onSuccess(String result) {
				try {
					PayPromptlyActivity.this.mCusProDialog.dismiss();
					JSONObject jsonObject = new JSONObject(result);
					PayPromptlyActivity.this.member_money = Double.valueOf(jsonObject.optString("data")).doubleValue();
					PayPromptlyActivity.this.tv_member_money.setText("(\uffe5"
							+ ComUtil.FormatDistance(new StringBuilder(String
									.valueOf(PayPromptlyActivity.this.member_money)).toString()) + ")");
					if (PayPromptlyActivity.this.member_money < Double.valueOf(
							PayPromptlyActivity.this.order.getPackage_price()).doubleValue()) {
						PayPromptlyActivity.this.img_yes_member
								.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
						PayPromptlyActivity.this.ll_member_money_no.setVisibility(0);
						PayPromptlyActivity.this.payType = 0;
						PayPromptlyActivity.this.ImgPayType(PayPromptlyActivity.this.img_weixin);
					} else {
						PayPromptlyActivity.this.img_yes_member.setVisibility(0);
						PayPromptlyActivity.this.ll_member_money_no
								.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
						PayPromptlyActivity.this.payType = BitmapCacheManagementTask.MESSAGE_FLUSH;
						PayPromptlyActivity.this.ImgPayType(PayPromptlyActivity.this.img_yes_member);
					}
					if (PayPromptlyActivity.this.temp == -1.0d) {
						if (PayPromptlyActivity.this.payType == 0) {
							if (LoadingActivity.welcome.getAwards().getWeixin() != null) {
								PayPromptlyActivity.this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(
										String.valueOf(Double.valueOf(PayPromptlyActivity.this.order.getPay_price())
												.doubleValue()
												- (LoadingActivity.welcome.getAwards().getWeixin().getPrice())))
										.toString()));
							} else {
								PayPromptlyActivity.this.tv_pay_money.setText(ComUtil
										.FormatDistance(PayPromptlyActivity.this.order.getPay_price()));
							}
						} else if (PayPromptlyActivity.this.payType != 1) {
							PayPromptlyActivity.this.tv_pay_money.setText(ComUtil
									.FormatDistance(PayPromptlyActivity.this.order.getPay_price()));
						} else if (LoadingActivity.welcome.getAwards().getAlipay() != null) {
							PayPromptlyActivity.this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(
									String.valueOf(Double.valueOf(PayPromptlyActivity.this.order.getPay_price())
											.doubleValue()
											- (LoadingActivity.welcome.getAwards().getAlipay().getPrice()))).toString()));
						} else {
							PayPromptlyActivity.this.tv_pay_money.setText(ComUtil
									.FormatDistance(PayPromptlyActivity.this.order.getPay_price()));
						}
					} else if (PayPromptlyActivity.this.payType == 0) {
						if (LoadingActivity.welcome.getAwards().getWeixin() != null) {
							PayPromptlyActivity.this.ll_weixin.performClick();
						} else {
							PayPromptlyActivity.this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(
									String.valueOf(PayPromptlyActivity.this.temp)).toString()));
						}
					} else if (PayPromptlyActivity.this.payType != 1) {
						PayPromptlyActivity.this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String
								.valueOf(PayPromptlyActivity.this.temp)).toString()));
					} else if (LoadingActivity.welcome.getAwards().getAlipay() != null) {
						PayPromptlyActivity.this.ll_alipay.performClick();
					} else {
						PayPromptlyActivity.this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String
								.valueOf(PayPromptlyActivity.this.temp)).toString()));
					}
				} catch (JSONException e) {
					e.printStackTrace();
				}
			}

			@Override
			public void onFail() {
				PayPromptlyActivity.this.mCusProDialog.dismiss();
				MainToast.show(PayPromptlyActivity.this,
						PayPromptlyActivity.this.getResources().getString(R.string.netFail), 0);
			}
		});
	}

	@Override
	public void onClick(View v) {
		Intent intent;
		switch (v.getId()) {
		case R.id.btn_back /* 2131165198 */:
			if (this.isOrder) {
				finish();
				return;
			}
			intent = new Intent(this, MainTWo.class);
			intent.putExtra("isgoorder", true);
			startActivity(intent);
		case R.id.ll_weixin /* 2131165204 */:
			this.isXianShang = true;
			ImgPayType(this.img_weixin);
			this.btn_ok.setText("\u7acb\u5373\u652f\u4ed8");
			this.payType = 0;
			setPayMoney();
		case R.id.ll_alipay /* 2131165340 */:
			this.isXianShang = true;
			ImgPayType(this.img_alipay);
			this.btn_ok.setText("\u7acb\u5373\u652f\u4ed8");
			this.payType = 1;
			setPayMoney();
		case R.id.btn_ok /* 2131165342 */:
			if (!this.isXianShang) {
				Map<String, String> map = new HashMap();
				map.put("id", this.order.getId());
				map.put("pay_type", "1");
				map.put("coupon_id", this.coupon_id);
				this.mCusProDialog.show();
				NetUtil.post(this, Constant.PAYSETTYPE, map, new RequestCallBack<String>() {
					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						PayPromptlyActivity.this.mCusProDialog.dismiss();
						try {
							JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
							if (jsonObject.getInt("code") == 10000) {
								Intent intent = new Intent(PayPromptlyActivity.this, MainTWo.class);
								intent.putExtra("isgoorder", true);
								PayPromptlyActivity.this.startActivity(intent);
								return;
							}
							MainToast.show(PayPromptlyActivity.this, jsonObject.optString("error"), 0);
						} catch (JSONException e) {
							e.printStackTrace();
						}
					}

					@Override
					public void onFailure(HttpException arg0, String arg1) {
						PayPromptlyActivity.this.mCusProDialog.dismiss();
						MainToast.show(PayPromptlyActivity.this,
								PayPromptlyActivity.this.getResources().getString(R.string.netFail), 0);
					}
				});
			} else if (Integer.parseInt(this.order.getStatus()) != 5) {
				intent = new Intent(this, MainTWo.class);
				intent.putExtra("isgoorder", true);
				startActivity(intent);
			} else if (this.payType == 0) {
				updateOrder("1");
			} else if (this.payType == 1) {
				updateOrder("2");
			} else if (this.payType == 2) {
				updateOrder("3");
			}
		case R.id.ll_quan_xuan /* 2131165373 */:
			Intent intent1 = new Intent(this, YouHuiMaActivity.class);
			intent1.putExtra("order_id", this.order.getId());
			intent1.putExtra("index_item", this.index_item);
			startActivityForResult(intent1, 333);
		case R.id.ll_yes_member /* 2131165376 */:
			if (this.member_money > Double.valueOf(this.order.getPackage_price()).doubleValue()) {
				this.isXianShang = true;
				ImgPayType(this.img_yes_member);
				this.btn_ok.setText("\u7acb\u5373\u652f\u4ed8");
				this.payType = 2;
				setPayMoney();
				return;
			}
			intent = new Intent(this, MemberTypeActivity.class);
			intent.putExtra("ispayprompty", true);
			intent.putExtra("isMemberRecharege", true);
			startActivityForResult(intent, 555);
		case R.id.ll_xianxia /* 2131165385 */:
			if (this.temp == -1.0d) {
				this.tv_pay_money.setText(ComUtil.FormatDistance(this.order.getPay_price()));
			} else {
				this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(this.temp))
						.toString()));
			}
			ImgPayType(this.img_xianxia);
			this.isXianShang = false;
			this.btn_ok.setText("\u7acb\u5373\u63d0\u4ea4");
		case R.id.ll_no_member /* 2131165387 */:
			intent = new Intent(this, MemberTypeActivity.class);
			intent.putExtra("ispayprompty", true);
			startActivityForResult(intent, 555);
		default:
		}
	}

	private void setPayMoney() {
		double aa = 0.0d;
		if (this.temp == -1.0d) {
			if (this.payType == 0) {
				if (LoadingActivity.welcome.getAwards().getWeixin() != null) {
					this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(Double.valueOf(
							this.order.getPay_price()).doubleValue()
							- (LoadingActivity.welcome.getAwards().getWeixin().getPrice()))).toString()));
				} else {
					this.tv_pay_money.setText(ComUtil.FormatDistance(this.order.getPay_price()));
				}
			} else if (this.payType != 1) {
				this.tv_pay_money.setText(ComUtil.FormatDistance(this.order.getPay_price()));
			} else if (LoadingActivity.welcome.getAwards().getAlipay() != null) {
				this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(Double.valueOf(
						this.order.getPay_price()).doubleValue()
						- (LoadingActivity.welcome.getAwards().getAlipay().getPrice()))).toString()));
			} else {
				this.tv_pay_money.setText(ComUtil.FormatDistance(this.order.getPay_price()));
			}
		} else if (this.payType == 0) {
			if (LoadingActivity.welcome.getAwards().getWeixin() != null) {
				if (this.temp - (LoadingActivity.welcome.getAwards().getWeixin().getPrice()) >= 0.0d) {
					aa = this.temp - (LoadingActivity.welcome.getAwards().getWeixin().getPrice());
				}
				this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(aa)).toString()));
				return;
			}
			this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(this.temp)).toString()));
		} else if (this.payType != 1) {
			this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(this.temp)).toString()));
		} else if (LoadingActivity.welcome.getAwards().getAlipay() != null) {
			if (this.temp - (LoadingActivity.welcome.getAwards().getAlipay().getPrice()) >= 0.0d) {
				aa = this.temp - (LoadingActivity.welcome.getAwards().getAlipay().getPrice());
			}
			this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(aa)).toString()));
		} else {
			this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(this.temp)).toString()));
		}
	}

	private void ImgPayType(ImageView img) {
		this.img_yes_member.setImageResource(R.drawable.icon_select);
		this.img_weixin.setImageResource(R.drawable.icon_select);
		this.img_xianxia.setImageResource(R.drawable.icon_select);
		this.img_alipay.setImageResource(R.drawable.icon_select);
		img.setImageResource(R.drawable.icon_select_p);
	}

	private void payMember() {
		this.cusProDialog.show();
		Map<String, String> map = new HashMap();
		map.put("id", this.orderid);
		NetUtil.post(this, Constant.PAYMEMBER, map, new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				PayPromptlyActivity.this.cusProDialog.dismiss();
				try {
					JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
					if (jsonObject.getInt("code") == 10000) {
						AppShareData.isPersonFrag = true;
						Intent intent = new Intent(PayPromptlyActivity.this, MainTWo.class);
						intent.putExtra("isgoorder", true);
						PayPromptlyActivity.this.startActivity(intent);
						return;
					}
					MainToast.show(PayPromptlyActivity.this, jsonObject.getString("error"), 0);
				} catch (JSONException e) {
					e.printStackTrace();
					MainToast.show(PayPromptlyActivity.this,
							PayPromptlyActivity.this.getResources().getString(R.string.app_error), 0);
				}
			}

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				PayPromptlyActivity.this.cusProDialog.dismiss();
				MainToast.show(PayPromptlyActivity.this,
						PayPromptlyActivity.this.getResources().getString(R.string.netFail), 0);
			}
		});
	}

	private void payWithAlipay() {
		String path = new StringBuilder(Constant.PAYALIPAY).append(this.order.getId()).toString();
		this.cusProDialog.show();
		NetUtil.get(this, path, 100, new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				PayPromptlyActivity.this.cusProDialog.dismiss();
				try {
					JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicodealipay(responseInfo.result));
					if (jsonObject.getInt("code") == 10000) {
						PayPromptlyActivity.this.payAlipayYes(jsonObject.optString("data"));
					} else {
						MainToast.show(PayPromptlyActivity.this, jsonObject.optString("error"), 0);
					}
				} catch (JSONException e) {
					e.printStackTrace();
					MainToast.show(PayPromptlyActivity.this, "\u670d\u52a1\u5668\u5fd9", 0);
				}
			}

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				PayPromptlyActivity.this.cusProDialog.dismiss();
				MainToast.show(PayPromptlyActivity.this,
						PayPromptlyActivity.this.getResources().getString(R.string.netFail), 0);
			}
		});
	}

	private void payAlipayYes(String info) {
		new AnonymousClass_12(info).start();
	}

	private void payWeixin() {
		String path = new StringBuilder(Constant.PAYWEIXIN).append(this.order.getId()).toString();
		this.cusProDialog.show();
		NetUtil.get(this, path, 100, new RequestCallBack<String>() {
			@Override
			public void onSuccess(ResponseInfo<String> responseInfo) {
				PayPromptlyActivity.this.cusProDialog.dismiss();
				try {
					JSONObject jsonObject = new JSONObject(NetUtil.unescapeUnicode(responseInfo.result));
					if (jsonObject.getInt("code") == 10000) {
						GetPrepayIdResult result = new GetPrepayIdResult();
						result.parseFrom(NetUtil.unescapeUnicode(responseInfo.result));
						PayPromptlyActivity.this.sendPayReq(result);
						return;
					}
					MainToast.show(PayPromptlyActivity.this, jsonObject.optString("error"), 0);
				} catch (JSONException e) {
					e.printStackTrace();
					MainToast.show(PayPromptlyActivity.this, "\u670d\u52a1\u5668\u5fd9", 0);
				}
			}

			@Override
			public void onFailure(HttpException arg0, String arg1) {
				PayPromptlyActivity.this.cusProDialog.dismiss();
				MainToast.show(PayPromptlyActivity.this,
						PayPromptlyActivity.this.getResources().getString(R.string.netFail), 0);
			}
		});
	}

	@Override
	protected void onResume() {
		if (code == 0) {
			code = -10000;
			MemberDetailActivity.code = -10000;
			Intent intent = new Intent(this, MainTWo.class);
			intent.putExtra("isgoorder", true);
			startActivity(intent);
		} else if (code != -10000) {
			code = -10000;
			MemberDetailActivity.code = -10000;
			MainToast.show(this, "\u652f\u4ed8\u672a\u6210\u529f", 0);
			checkNet();
		}
		super.onResume();
	}

	@Override
	protected void onStart() {
		super.onStart();
	}

	private void updateOrder(String pay_method) {
		Map<String, String> map = new HashMap();
		map.put("id", this.order.getId());
		map.put("pay_type", "2");
		map.put("coupon_id", this.coupon_id);
		map.put("pay_method", pay_method);
		NetUtil.post(this, Constant.PAYSETTYPE, map, new AnonymousClass_14(pay_method));
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		double aa = 0.0d;
		super.onActivityResult(requestCode, resultCode, data);
		if (requestCode == 555 && resultCode == -1) {
			initMemberData();
		}
		if (requestCode == 333) {
			if (resultCode == 0 && this.quanResults == null) {
				getQuanShu();
			}
			if (resultCode == -1) {
				this.quanResults = (QuanResults) data.getExtras().getSerializable("quanResults");
				this.index_item = data.getExtras().getInt("index");
				if (this.quanResults != null) {
					this.temp = Double.valueOf(this.order.getPackage_price()).doubleValue()
							- Double.valueOf(this.quanResults.getDiscount()).doubleValue();
					if (this.temp <= 0.0d) {
						this.temp = 0.0d;
					}
					this.coupon_id = this.quanResults.getId();
					if (!this.isXianShang) {
						this.ll_xianxia.performClick();
					} else if (this.payType == 0) {
						if (LoadingActivity.welcome.getAwards().getWeixin() != null) {
							if (this.temp - (LoadingActivity.welcome.getAwards().getWeixin().getPrice()) >= 0.0d) {
								aa = this.temp - (LoadingActivity.welcome.getAwards().getWeixin().getPrice());
							}
							this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(aa))
									.toString()));
						} else {
							this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String
									.valueOf(this.temp)).toString()));
						}
					} else if (this.payType != 1) {
						this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(this.temp))
								.toString()));
					} else if (LoadingActivity.welcome.getAwards().getAlipay() != null) {
						if (this.temp - (LoadingActivity.welcome.getAwards().getAlipay().getPrice()) >= 0.0d) {
							aa = this.temp - (LoadingActivity.welcome.getAwards().getAlipay().getPrice());
						}
						this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(aa))
								.toString()));
					} else {
						this.tv_pay_money.setText(ComUtil.FormatDistance(new StringBuilder(String.valueOf(this.temp))
								.toString()));
					}
					this.tv_youhui_name.setText("\u7701" + this.quanResults.getDiscount() + "\u5143("
							+ this.quanResults.getCoupon().getName() + ")");
					return;
				}
				this.temp = -1.0d;
				if (this.isXianShang) {
					setPayMoney();
				} else {
					this.ll_xianxia.performClick();
				}
				this.coupon_id = "";
				getQuanShu();
			}
		}
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == 4) {
			if (this.isOrder) {
				finish();
			} else {
				Intent intent = new Intent(this, MainTWo.class);
				intent.putExtra("isgoorder", true);
				startActivity(intent);
			}
		}
		return true;
	}

	private void sendPayReq(GetPrepayIdResult result) {
		PayReq req = new PayReq();
		req.appId = Constants.APP_ID;
		req.partnerId = Constants.PARTNER_ID;
		req.prepayId = result.prepayId;
		req.nonceStr = result.noncestr;
		req.timeStamp = result.timestamp;
		req.packageValue = "Sign=WXPay";
		req.sign = result.sign;
		this.api.sendReq(req);
	}
}